import axios from 'axios';
import {
  DepartmentAddCmd,
  DepartmentListQry,
  DepartmentQry,
  DepartmentTreeQry,
  DepartmentUptCmd,
  DepartmentView,
} from '@/types/idm/department';
import qs from 'query-string';

export function createDepartment(data: DepartmentAddCmd) {
  return axios.post<DepartmentView>('/idm/organization/department', data);
}

export function updateDepartment(data: DepartmentUptCmd) {
  return axios.put<DepartmentView>('/idm/organization/department', data);
}

export function fetchDepartment(params: DepartmentQry) {
  return axios.get<DepartmentView>('/idm/organization/department/one', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}

export function fetchDepartmentList(params: DepartmentListQry) {
  return axios.get<DepartmentView[]>('/idm/organization/department/list', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}

export function fetchDepartmentAllTree(params: DepartmentTreeQry) {
  return axios.get<DepartmentView[]>('/idm/organization/department/tree-all', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}
